 import { PASS_LIST_SLIDE,GET_VISA_CATEGORY,GET_PROVINCE_LIST,GET_DEFAULT_ADDRESS} from "./actionsTypes";
 export const passListSlide = data => ({type: PASS_LIST_SLIDE, data: data});
 export const getVisaCategory = data => ({type: GET_VISA_CATEGORY, data: data});
 export const getProvinceList = data => ({type: GET_PROVINCE_LIST, data: data});
 export const getDefaultAddress = data => ({type: GET_DEFAULT_ADDRESS, data: data});

import homeService from  '../services/homeService';
import {Toast} from 'antd-mobile'

//通行证列表
export const passList=(data,callBack)=>{
	 return (dispatch, getState)=> {
		Toast.hide();
		Toast.loading("", 30, () => Toast.info("网络错误", 2));
		homeService.passList(data).then(resultData => {
			Toast.hide();
			if (resultData.code == 1000) {
				callBack&&callBack(resultData.body.hkmPassMsgList)

				dispatch(passListSlide(resultData.body.hkmPassMsgList))
			} else {
				Toast.info(resultData.msg, 1)
			}
		})
	 }
}

 //通过获取收费规则获取签注次数等信息（通过签注类别和省ID获得种类）
 export const getCategory=(data,callBack)=>{
	 return (dispatch, getState)=> {
		 Toast.hide();
		 Toast.loading("", 30, () => Toast.info("网络错误", 2));
		 homeService.getCategory(data).then(resultData => {
			 Toast.hide();
			 if (resultData.code == 1000) {
				 // dispatch(getVisaCategory(resultData.body.chargeRuleList))
				  callBack(resultData.body.chargeRuleList)
			 } else {
				 Toast.info(resultData.msg, 1)
			 }
		 })
	 }
 }

 //全量或按照省份id获取地市列表
 export const provinceList=(data,callBack)=>{
	 return (dispatch, getState)=> {
		 Toast.hide();
     Toast.loading("", 30, () => Toast.info("网络错误", 2));
		 homeService.getProvinceList(data).then(resultData => {
			 Toast.hide();
			 if (resultData.code == 1000) {
				 dispatch(getProvinceList(resultData.body.areaMsgList))
			 } else {
				 Toast.info(resultData.msg, 1)
			 }
		 })
	 }
 }

 //获取默认地址
 export const defaultAddress=(data,callBack)=>{
	 return (dispatch, getState)=> {
		 Toast.hide();
		 Toast.loading("", 30, () => Toast.info("网络错误", 2));
		 homeService.defaultAddress(data).then(resultData => {
			 Toast.hide();
			 if (resultData.code == 1000) {
				 dispatch(getDefaultAddress(resultData.body))
				 callBack&&callBack()
			 } else {
				 Toast.info(resultData.msg, 1)
			 }
		 })
	 }
 }

 //提交表单
 export const subMitForm=(data,callBack)=>{
	 return (dispatch, getState)=> {
		 Toast.hide();
	   Toast.loading("", 30, () => Toast.info("网络错误", 2));
		 homeService.subMitForm(data).then(resultData => {
			 Toast.hide();
			 if (resultData.code == 1000) {
				 callBack&&callBack(resultData.body)
			 } else {
				 Toast.info(resultData.msg, 1)
			 }
		 })
	 }
 }


